package com.bp.hearthealth.pulse.lnapps.bp_ui.bp_dialog

import android.app.Activity
import android.app.Dialog
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import androidx.databinding.DataBindingUtil
import com.bp.hearthealth.pulse.lnapps.R
import com.bp.hearthealth.pulse.lnapps.databinding.DeleteLayoutBgBinding
import com.bp.hearthealth.pulse.lnapps.bp_utils.DoubleClickListener

class BpDeleteDialog(context: Activity) {
    private lateinit var binding: DeleteLayoutBgBinding
    private lateinit var onCliclLisener: OnBtnClickListener
    private lateinit var dialog: Dialog
    private val activity: Activity = context

    fun showDialog() {
        dialog = Dialog(activity, R.style.My_Dialog_FullScreen)
        binding = DataBindingUtil.inflate(LayoutInflater.from(activity),
            R.layout.delete_layout_bg,
            null,
            false)
        binding.root.let { dialog.setContentView(it) }//核心代码
        dialog.setCanceledOnTouchOutside(false)
        dialog.setCancelable(false)
        val lp = dialog.window?.attributes
        lp?.width = WindowManager.LayoutParams.MATCH_PARENT
        lp?.height = WindowManager.LayoutParams.WRAP_CONTENT

        lp?.alpha = 1f
        dialog.window?.attributes = lp
        if (activity.isFinishing) {
            return
        }
        dialog.show()
        binding.tvCancel.setOnClickListener(object : DoubleClickListener() {
            override fun onNoDoubleClick(v: View?) {
                dialog.dismiss()
            }
        })
        binding.tvOk.setOnClickListener(object : DoubleClickListener() {
            override fun onNoDoubleClick(v: View?) {
                onCliclLisener.onBtnClick()
            }
        })
    }

    fun dismiss() {
        dialog.dismiss()
    }
    fun setOnBtnClickLisener(clickListener: OnBtnClickListener) {
        this.onCliclLisener = clickListener
    }
    interface OnBtnClickListener {
        fun onBtnClick()
    }
}
